package com.example.mushroom.controller;

import com.example.mushroom.entity.Device;
import com.example.mushroom.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/devices")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @PostMapping
    public int insertDevice(@RequestBody Device device) {
        return deviceService.insertDevice(device);
    }

    @GetMapping("/{id}")
    public Device selectDeviceById(@PathVariable Integer id) {
        return deviceService.selectDeviceById(id);
    }

    @GetMapping
    public List<Device> selectAllDevices() {
        return deviceService.selectAllDevices();
    }

    @PutMapping
    public int updateDevice(@RequestBody Device device) {
        return deviceService.updateDevice(device);
    }

    @DeleteMapping("/{id}")
    public int deleteDeviceById(@PathVariable Integer id) {
        return deviceService.deleteDeviceById(id);
    }

    @GetMapping("/page")
    public List<Device> selectDevicesByPage(@RequestParam int offset, @RequestParam int limit) {
        return deviceService.selectDevicesByPage(offset, limit);
    }
}